package Homework.day01;

import java.util.Scanner;

/**
 * 要求用户在控制台输入自己的用户名。
 * 然后要求做如下验证工作:
 * 1:用户名不能为空(只要有一个字符)
 * 2:用户名必须在20个字以内
 * @author Xiloer
 *
 */
public class Test02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter your Username: ");
        String username = sc.nextLine();
        while(checkUsername(username)){
            username = sc.nextLine();
        }
    }
    public static boolean checkUsername(String username) {
        if(username.equals("")) {
            System.out.println("Your username is empty, please enter a valid username!");
            return true;
        }else if(username.length() > 20){
            System.out.println("Your username is too long, please enter a valid username!");
            return true;
        }else {
            System.out.println("Your username is valid!");
            return false;
        }
    }
}
